package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IUnitGroupDao;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.pojo.UnitGroup;
import com.hy.erp.inventory.pojo.interfaces.IUnitGroup;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.service.interfaces.IUnitGroupService;

/**
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-12；时间：上午09:35:52</li>
 * <li>字段类型：long；字段名称：serialVersionUID</li>
 * <li>设计目的：单元组维护服务</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Name("unitGroupService")
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class UnitGroupService
								extends
								AbstractBusinessService < IUnitGroup >
																		implements
																		IUnitGroupService
{

	private static final long	serialVersionUID	=
														- 8783233206377348205L ;

	/**
	 * 
	 * 构造函数
	 */
	public UnitGroupService()
	{
		super ( );
	}
	
	@ Override
	public boolean addUnitGroup (
									UnitGroup unitGroup )
	{
		if(unitGroup==null)
		{
			return true;
		}
		else
		{
			IUnitGroupDao dao=( IUnitGroupDao ) this.getDao ( IUnitGroup.class );
			IUnitGroup iUnitGroup= unitGroup;
			return dao.persist ( iUnitGroup ) ;
		}
	}

	@ Override
	public Integer removeUnitGroup (
										String [ ] unitGroupIds )
	{
		if ( ( null == unitGroupIds )
			     || ( unitGroupIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				IUnitGroupDao dao=( IUnitGroupDao ) this.getDao ( IUnitGroup.class );
				return dao.remove ( unitGroupIds );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyUnitGroup (
										UnitGroup unitGroup )
	{
		if ( ( null == unitGroup ) || ( null == unitGroup.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			IUnitGroupDao dao=( IUnitGroupDao ) this.getDao ( IUnitGroup.class );
			IUnitGroup iUnitGroup= unitGroup;
			if ( null == iUnitGroup )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( iUnitGroup )!=null) ;
		}
	}

	@ Override
	public String [ ] addUnitGroup (
										Object [ ] objects )
	{
		IUnitGroupDao dao=( IUnitGroupDao ) this.getDao ( IUnitGroup.class );
		UnitGroup[] groups=new UnitGroup[objects.length];
		for ( int i =
						0 ; i < objects.length ; i ++ )
		{
			UnitGroup unitGroup=( UnitGroup ) objects[i];
			groups[i]=unitGroup;
		}
		return dao.persist ( groups ) ;
	}

	@ Override
	public List < IUnitGroup > getAllUnitGroup ( )
	{
		IUnitGroupDao dao=( IUnitGroupDao ) this.getDao ( IUnitGroup.class );
		return dao.find ( ) ;
	}

	@ Override
	public String [ ] modifyUnitGroup (
										Object [ ] objects )
	{

		if (  null == objects ) 
				{
					return null;
				}
				else
				{
					IUnitGroupDao dao=( IUnitGroupDao ) this.getDao ( IUnitGroup.class );
					UnitGroup[] groups=new UnitGroup[objects.length];
		            for(int i=0;i<objects.length;i++)
		            {
		            	UnitGroup type=( UnitGroup ) objects[i];
		            	groups[i]=type;
		            }
					
					return dao.merge ( groups );
				}
	}

}
